﻿using Admin40000.Domain.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Admin40000.Domain
{
    public class DbInitializeHelper
    {
        public static void Initializer() 
        {
            using (var db=new Admin40000DbContext())
            {
                var dbExise = db.Database.EnsureCreated();
                var tempBrand = db.Brands.Any();
                if (!tempBrand) 
                {
                    var brand = new Brand
                    {
                        BrandName = "Apple",
                        Descrtion = "美国的一个大品牌，相当牛逼"
                    };
                    db.Brands.Add(brand);
                    db.SaveChanges();

                    db.Products.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName="Ipone X 红色",
                        ShortDesc="这是一个商品简介",
                        FullDesc="这是商品详情",
                        BrandId=brand.Id

                    },
                    new Product
                    {
                        ProductName="Ipone X 绿色",
                        ShortDesc="这是一个商品简介",
                        FullDesc="这是商品详情",
                        BrandId=brand.Id

                    }
                    });
                    db.SaveChanges();
                }
                
            }
        }
    }
}
